package com.telit.common.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * @Auther amy
 * @Describe 格式化校验
 */
public class RegexUtils {

    /** 小写英文、数字组成、短横线的字符串 */
    public static final String STRING_LETTER_LOWER_NUMBER = "^[a-z0-9-]+$";

    /** 手机号校验格式 **/
    public static final String MOBILE_REGEX = "^[1][3,4,5,6,7,8,9][0-9]{9}$";

    /** 座机号码格式校验 **/
    public static final String MOBILE_PHONE_REGEX = "^\\d{3}-\\d{7,8}|\\d{4}-\\d{7,8}$";
//    public static final String MOBILE_PHONE_REGEX = "^[0][1-9]{2,3}-[0-9]{5,10}$)|(^[0][0-9]{2,3}[0-9]{5,10}$)|(^[0-9]{5,10}$";

    /** 电台呼号格式校验 **/
    public static final String RADIO_STATION_PHONE_REGEX = "^[A-Za-z]{2,3}\\d+[.]?\\d*$";

    /** 密码正则：数字字母数字,长度在6到12位 **/
//    public static final String PASSWORD_REGEX = "^(?=.*[0-9].*)(?=.*[A-Z].*)(?=.*[a-z].*).{6,12}$";
    /** 密码正则：大小写字母数字加特殊字符,8位以上 **/
    public static final String PASSWORD_REGEX = "\"^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[~!@#$%^&*_.]).{8,12}$\"";

    /** ip 校验规则 **/
    public static final String IP_REGEX = "^((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)$";

    public static boolean match(String regex, String str) {
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
    }

    public static void main(String[] args) {
        // 包含大小写字母，数字特殊字符
        String regix = "^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[~!@#$%^&*_.]).{8,}$";
        String str = "T1234567!@";
        System.out.println(match(regix,str));

    }
}
